package Array;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Classname 等差子数组1630
 * @Description TODO
 * @Date 2023/3/23 19:54
 * @Created by xjl
 */
public class 等差子数组1630 {

    public List<Boolean> checkArithmeticSubarrays(int[] nums, int[] l, int[] r) {
        ArrayList<Boolean> result=new ArrayList<>();
        for (int i=0,j=0;i<l.length;i++,j++){
            if (check(nums,l[i],r[j])){
                result.add(true);
            }else {
                result.add(false);
            }
        }
        return result;
    }

    private boolean check(int[] nums, int l, int r) {
        ArrayList<Integer> list=new ArrayList<>();
        for (int i=l;i<=r;i++){
            list.add(nums[i]);
        }
        Collections.sort(list);
        int count=list.get(1)-list.get(0);
        for (int i=1;i<list.size();i++){
            if (list.get(i)-count!=list.get(i-1)){
                return false;
            }
        }
        return true;
    }

    @Test
    public void test(){
        List<Boolean> booleans = checkArithmeticSubarrays(new int[]{4, 6, 5, 9, 3, 7}, new int[]{0, 0, 2}, new int[]{2, 3, 5});

    }
}
